using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Xml;
using System.Xml.XPath;

namespace Umbraco.Ecommerce.DataControls
{
	public class ProductEditor : System.Web.UI.WebControls.WebControl, umbraco.interfaces.IData, umbraco.interfaces.IDataEditor, umbraco.interfaces.IDataType,umbraco.interfaces.IDataPrevalue
	{
		private UmbracoProductControl c;
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);
			try 
			{	
				c = (UmbracoProductControl) this.Page.LoadControl(umbraco.GlobalSettings.Path + "/StoreAdministration/UmbracoProductControl.ascx");
				c.Node = new umbraco.cms.businesslogic.Content(int.Parse(umbraco.helper.Request("id")));
				this.Controls.Add(c);
			} 
			catch (Exception ex) {
				this.Controls.Add(new LiteralControl("Error loading control<br /> " + ex.ToString()));
			}
		}

		#region IData Members
		public System.Xml.XmlNode ToXMl(System.Xml.XmlDocument d)
		{
			return d.CreateTextNode(" ");
		}

		public object Value
		{
			get
			{return "";}
			set	{}
		}

		public void MakeNew(int PropertyId)
		{
			// TODO:  Add ProductEditor.MakeNew implementation
		}

		private int _propertyid;

		
		public int PropertyId
		{
			set
			{
				_propertyid = value;
			}
		}

		public void Delete()
		{
			// TODO:  Add ProductEditor.Delete implementation
		}

		#endregion

		#region IDataEditor Members

		public Control Editor
		{
			get
			{
				return this;
			}
		}

		void umbraco.interfaces.IDataEditor.Save()
		{
			c.SaveInfo();
		}

		public bool TreatAsRichTextEditor
		{
			get
			{
				return false;
			}
		}

		public bool ShowLabel {
			get {return false;}
		}
		#endregion

		#region IDataType Members

		public umbraco.interfaces.IData Data
		{
			get
			{
				return this;
			}
		}

		public virtual Guid Id 
		{
			get {return new Guid("F8D60F68-EC59-4974-B43B-C46EB5677998");}
		}
		
		public umbraco.interfaces.IDataEditor DataEditor
		{
			get
			{
				return this;
			}
		}

		private int _datatypedefinitionid;

		public int DataTypeDefinitionId
		{
			set
			{
				_datatypedefinitionid = value;
			}
			get {
				return _datatypedefinitionid;	
			}
		}

		public virtual string DataTypeName 
		{
			get {return "Product datatype";}
		}

		

		public umbraco.interfaces.IDataPrevalue PrevalueEditor
		{
			get
			{
				return this;
			}
		}

		#endregion

		#region IDataPrevalue Members

		void umbraco.interfaces.IDataPrevalue.Save()
		{
			
		}

		#endregion
	}
}